package com.manager.book;

import java.util.ArrayList;
import java.util.List;
import java.util.ArrayList;
import java.util.List;

public class BookManager {
	private static BookManager instance;

	public static BookManager me() {
		if (instance == null) {
			instance = new BookManager();
		}
		return instance;
	}

	private static List<Book> books;

	private BookManager() {
		books = new ArrayList<>();
	}

	public static void addBook(Book book) {
		books.add(book);
	}

	public static void deleteBook(int bookId) {
		books.removeIf(book -> book.getId() == bookId);
	}

	public static void updateBook(int bookId, Book updatedBook) {
		for (Book book : books) {
			if (book.getId() == bookId) {
				book.setTitle(updatedBook.getTitle());
				book.setAuthor(updatedBook.getAuthor());
				break;
			}
		}
	}

	public static Book getBook(int bookId) {
		for (Book book : books) {
			if (book.getId() == bookId) {
				return book;
			}
		}
		return null;
	}

	public static List<Book> getAllBooks() {
		return books;
	}
}